package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RentalSysReturnRecords;
import com.ruoyi.system.service.IRentalSysReturnRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 归还记录Controller
 * 
 * @author Mag1c_-xyy
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/returnRecords")
public class RentalSysReturnRecordsController extends BaseController
{
    @Autowired
    private IRentalSysReturnRecordsService rentalSysReturnRecordsService;

    /**
     * 查询归还记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:returnRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalSysReturnRecords rentalSysReturnRecords)
    {
        startPage();
        List<RentalSysReturnRecords> list = rentalSysReturnRecordsService.selectRentalSysReturnRecordsList(rentalSysReturnRecords);
        return getDataTable(list);
    }

    /**
     * 导出归还记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:returnRecords:export')")
    @Log(title = "归还记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentalSysReturnRecords rentalSysReturnRecords)
    {
        List<RentalSysReturnRecords> list = rentalSysReturnRecordsService.selectRentalSysReturnRecordsList(rentalSysReturnRecords);
        ExcelUtil<RentalSysReturnRecords> util = new ExcelUtil<RentalSysReturnRecords>(RentalSysReturnRecords.class);
        util.exportExcel(response, list, "归还记录数据");
    }

    /**
     * 获取归还记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:returnRecords:query')")
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Long returnId)
    {
        return success(rentalSysReturnRecordsService.selectRentalSysReturnRecordsByReturnId(returnId));
    }

    /**
     * 新增归还记录
     */
    @PreAuthorize("@ss.hasPermi('system:returnRecords:add')")
    @Log(title = "归还记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalSysReturnRecords rentalSysReturnRecords)
    {
        return toAjax(rentalSysReturnRecordsService.insertRentalSysReturnRecords(rentalSysReturnRecords));
    }

    /**
     * 修改归还记录
     */
    @PreAuthorize("@ss.hasPermi('system:returnRecords:edit')")
    @Log(title = "归还记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalSysReturnRecords rentalSysReturnRecords)
    {
        return toAjax(rentalSysReturnRecordsService.updateRentalSysReturnRecords(rentalSysReturnRecords));
    }

    /**
     * 删除归还记录
     */
    @PreAuthorize("@ss.hasPermi('system:returnRecords:remove')")
    @Log(title = "归还记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{returnIds}")
    public AjaxResult remove(@PathVariable Long[] returnIds)
    {
        return toAjax(rentalSysReturnRecordsService.deleteRentalSysReturnRecordsByReturnIds(returnIds));
    }
}
